﻿using System;
using System.Runtime.InteropServices;

namespace negoserverjni
{ 
    static unsafe class Delegates
    {
        //Exported methods via delegates
        static public StringtoArray_delegate stringtoarray;
        static public TranslateNameIntoSid_delegate translatenameintosid;
        static public TranslateSidIntoName_delegate translatesidintoname;
        static public Accept_sec_delegate accept_sec;
        static public FreeAuthenticator_delegate freeauthenticator;
        static public Login_delegate login;
        //JNI Pointer function
        //static public GetStringChars getStringChars;
        //static public GetStringCritical getStringCritical;
        //static public ReleaseStringChars releaseStringChars;
        //static public ReleaseStringCritical releaseStringCritical;
        static public NewByteArray newByteArray;
        static public NewCharArray newCharArray;
        static public SetByteArrayRegion setByteArrayRegion;
        static public SetCharArrayRegion setCharArrayRegion;
        static public RegisterNatives registerNatives;
        static public NewString newString;
        //static public GetPrimitiveArrayCritical getPrimitiveArrayCritical;
        //static public ReleasePrimitiveArrayCritical releasePrimitiveArrayCritical;
        static public GetArrayLength getArrayLength;
        //static public GetByteArrayElements getByteArrayElements;
        static public GetByteArrayRegion getByteArrayRegion;
        static public GetStringLength getStringLength;
        static public GetStringRegion getStringRegion;
        static public GetObjectArrayElement getObjectArrayElement;
        static public SetObjectArrayElement setObjectArrayElement;
        static public NewBooleanArray newBooleanArray;
        static public SetBooleanArrayRegion setBooleanArrayRegion;
        static public SetLongArrayRegion setLongArrayRegion;


        /// Return Type: void*
        static public void MapFunctionPointerForDelegate(JNINativeInterface_* jninativeinterface/*, IntPtr classz*/)
        {
            //getStringChars = (GetStringChars)Marshal.GetDelegateForFunctionPointer(jninativeinterface->GetStringChars, typeof(GetStringChars));
            //getStringCritical = (GetStringCritical)Marshal.GetDelegateForFunctionPointer(jninativeinterface->GetStringCritical, typeof(GetStringCritical));
            //releaseStringChars = (ReleaseStringChars)Marshal.GetDelegateForFunctionPointer(jninativeinterface->ReleaseStringChars, typeof(ReleaseStringChars));
            //releaseStringCritical = (ReleaseStringCritical)Marshal.GetDelegateForFunctionPointer(jninativeinterface->ReleaseStringCritical, typeof(ReleaseStringCritical));
            newByteArray = (NewByteArray)Marshal.GetDelegateForFunctionPointer(jninativeinterface->NewByteArray, typeof(NewByteArray));
            newCharArray = (NewCharArray)Marshal.GetDelegateForFunctionPointer(jninativeinterface->NewCharArray, typeof(NewCharArray));

            setByteArrayRegion = (SetByteArrayRegion)Marshal.GetDelegateForFunctionPointer(jninativeinterface->SetByteArrayRegion, typeof(SetByteArrayRegion));
            setCharArrayRegion = (SetCharArrayRegion)Marshal.GetDelegateForFunctionPointer(jninativeinterface->SetCharArrayRegion, typeof(SetCharArrayRegion));
            registerNatives = (RegisterNatives)Marshal.GetDelegateForFunctionPointer(jninativeinterface->RegisterNatives, typeof(RegisterNatives));
            newString = (NewString)Marshal.GetDelegateForFunctionPointer(jninativeinterface->NewString, typeof(NewString));
            //getPrimitiveArrayCritical = (GetPrimitiveArrayCritical)Marshal.GetDelegateForFunctionPointer(jninativeinterface->GetPrimitiveArrayCritical, typeof(GetPrimitiveArrayCritical));
            //releasePrimitiveArrayCritical = (ReleasePrimitiveArrayCritical)Marshal.GetDelegateForFunctionPointer(jninativeinterface->ReleasePrimitiveArrayCritical, typeof(ReleasePrimitiveArrayCritical));
            getArrayLength = (GetArrayLength)Marshal.GetDelegateForFunctionPointer(jninativeinterface->GetArrayLength, typeof(GetArrayLength));
            //getByteArrayElements = (GetByteArrayElements)Marshal.GetDelegateForFunctionPointer(jninativeinterface->GetByteArrayElements, typeof(GetByteArrayElements));
            getByteArrayRegion = (GetByteArrayRegion)Marshal.GetDelegateForFunctionPointer(jninativeinterface->GetByteArrayRegion, typeof(GetByteArrayRegion));
            getStringLength = (GetStringLength)Marshal.GetDelegateForFunctionPointer(jninativeinterface->GetStringLength, typeof(GetStringLength));
            getStringRegion = (GetStringRegion)Marshal.GetDelegateForFunctionPointer(jninativeinterface->GetStringRegion, typeof(GetStringRegion));
            getObjectArrayElement = (GetObjectArrayElement)Marshal.GetDelegateForFunctionPointer(jninativeinterface->GetObjectArrayElement, typeof(GetObjectArrayElement));
            setObjectArrayElement = (SetObjectArrayElement)Marshal.GetDelegateForFunctionPointer(jninativeinterface->SetObjectArrayElement, typeof(SetObjectArrayElement));
            newBooleanArray = (NewBooleanArray)Marshal.GetDelegateForFunctionPointer(jninativeinterface->NewBooleanArray, typeof(NewBooleanArray));
            setBooleanArrayRegion = (SetBooleanArrayRegion)Marshal.GetDelegateForFunctionPointer(jninativeinterface->SetBooleanArrayRegion, typeof(SetBooleanArrayRegion));
            setLongArrayRegion = (SetLongArrayRegion)Marshal.GetDelegateForFunctionPointer(jninativeinterface->SetLongArrayRegion, typeof(SetLongArrayRegion));
        }
    }
}
